package com.hzit.bj1804.dianservice.controller;

import com.hzit.bj1804.dian.entity.Productcategory;
import com.hzit.bj1804.dianservice.service.ProductategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: dian
 * @description:
 * @author: zhz
 * @create: 2018-12-01 13:47
 **/
@Controller
public class ProductategoryController {
    @Autowired
    private ProductategoryService productategoryService;

    /**
     * 查询所有类别
     * @return
     */
    @RequestMapping("/get_type")
    @ResponseBody
    public List<Productcategory> getProductategory(){
        List<Productcategory> allType = productategoryService.findAllType();
        return allType;
    }

    /**
     * 分页查询
     * @return
     */
    @RequestMapping("probypage")
    @ResponseBody
    public Object getProductategoryByPage(@RequestParam("limit")int limit,@RequestParam("page")int page){
        return productategoryService.findAllTypePage(limit,page);
    }

    /**
     * 根据ID查询
     * @param categoryid
     * @return
     */
    @RequestMapping("findByid")
    @ResponseBody
    public Object getProductategoryById(@RequestParam("categoryid") int categoryid){
        List<Productcategory> byId = productategoryService.findById(categoryid);
        return byId;
    }
    @RequestMapping("byIdAndName")
    @ResponseBody
    public Object getProductategoryByIdAndName(@RequestParam("categoryname") String categoryname){
        List<Productcategory> byIdAndName = productategoryService.findByIdAndName(categoryname);
        return byIdAndName;
    }

    /**修改所有类型信息
     * @param productcategory
     * @return
     */
    @RequestMapping("uptype")
    @ResponseBody
    public Object updateProductategory(@RequestBody Productcategory productcategory){
        int i = productategoryService.updateProductcatgoryType(productcategory);
        return i;
    }

    /**
     * 添加类别
     * @param productcategory
     * @return
     */
    @RequestMapping("addtype")
    @ResponseBody
    public Object addProductategory(@RequestBody Productcategory productcategory){
        int i = productategoryService.addProductcatgoryType(productcategory);
        return i;
    }
    /**
     * 修改状态
     * @param categoryid
     * @return
     */
    @RequestMapping("delup")
    @ResponseBody
    public Object delUpStatus(@RequestParam("categoryid") int categoryid){
        int i = productategoryService.deletProducatgoryStatus(categoryid);
        return i;
    }


}
